 #include<stdio.h>
  #include<unistd.h>
  #include<fcntl.h>
  #include<stdlib.h>
  #include<errno.h>
  #include<string.h>
  #include<sys/stat.h>
  int main(){ 
	  //close(0);    //close stdin
	  close(1);     //close stdout
      umask(0); //cancel system umask 
      //"w" = O_WRONLY(write file) + O_CREAT(create file) +  O_TRUNC (clean file)
      //"a" = O_WRONLY(write file) + O_CREAT(create file) +  O_APPEND (append file)
      //"r" = O_RDONLY(read file) 
      int fd = open("log.txt",O_WRONLY | O_CREAT | O_TRUNC ,0666);
	  printf("fd :%d\n", fd);
	  fprintf(stdout," fd :%d\n",fd);
	  //User forced refresh
	  //fclose(stdout); //All buffers have been refreshed
	  fflush(stdout);
      close(fd);
      return 0;
  }

